package com.itheima.mynetty.codec;

import com.itheima.netty.pojo.UserInfo;
import com.itheima.netty.util.ProtostuffUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import java.util.List;

public class ProtoStuffDecoder extends MessageToMessageDecoder<ByteBuf> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
        byte[] bytes = new byte[msg.readableBytes()];
        msg.readBytes(bytes);
        UserInfo userInfo = ProtostuffUtil.deserialize(bytes, UserInfo.class);
        out.add(userInfo);
    }
}
